package UIComponents// ActionScript file
{
	import MyComponent.MyButton;
	
	import fl.events.ComponentEvent;
	
	import flash.display.Sprite;
	import flash.text.TextField;

	public class ListItems extends Sprite
	{
		private var _nowPage:int=1;/*当前页数*/
		private var _maxPage:int;/*最大页数*/
		public function ListItems():void
		{
			this.init();
		}
		
		private function init():void
		{
			this.addListener();
		}
		
		private function addListener():void
		{
			(this.getChildByName("buttonLeft") as MyButton).addEventListener(ComponentEvent.BUTTON_DOWN,turnLeftHandler);
			(this.getChildByName("buttonRight") as MyButton).addEventListener(ComponentEvent.BUTTON_DOWN,turnRightHandler);
		}

		private function removeListener():void
		{
			(this.getChildByName("buttonLeft") as MyButton).removeEventListener(ComponentEvent.BUTTON_DOWN,turnLeftHandler);
			(this.getChildByName("buttonRight") as MyButton).removeEventListener(ComponentEvent.BUTTON_DOWN,turnRightHandler);
		}
		
		private function turnLeftHandler(e:ComponentEvent):void
		{
			this.nowPage+=1;
		}
		
		private function turnRightHandler(e:ComponentEvent):void
		{
			this.nowPage-=1;
		}
		
		public function getFrameItemByIndex(index:int):FrameItem
		{
			if(index<0 || index>8)throw new Error("索引出错");
			return (this.getChildByName("frameItem_"+index)) as FrameItem;
		}
		
		public function release():void
		{
			
		}
		
		public function updatePage():void
		{
			(this.getChildByName("txt_page") as TextField).text=this.nowPage+"/"+this.maxPage;
		}

		public function get nowPage():int
		{
			return _nowPage;
		}

		public function set nowPage(value:int):void
		{
			if(value<0 || value>this.maxPage)return;
			_nowPage = value;
			this.updatePage();
		}

		public function get maxPage():int
		{
			return _maxPage;
		}

		public function set maxPage(value:int):void
		{
			if(value<0) return;
			_maxPage = value;
			this.updatePage();
		}


	}
}